import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class MotorsDriver {

	public static void main(String[] args) {
		Motor aMotor = new Motor("AA", 100);

		Motor secondMotor = new Motor("BB", 30);
		secondMotor.addHours(35);

		List<Motor> allMotors = new ArrayList<Motor>();

		allMotors.add(aMotor);
		allMotors.add(secondMotor);

//		aMotor = null;

		for (Motor someMotor : allMotors) {
			if (someMotor.isPastTimeForService() == true) {
				System.out.println(someMotor.getSerialNumber());
			}
		}

		int numberOfItems = allMotors.size();
		System.out.println("Size of list is " + numberOfItems);

		for (int i = 0; i < allMotors.size(); i++) {
			Motor firstMotor = allMotors.get(i);
			System.out.println(firstMotor);
		}
		
		Motor motorToUpdate = allMotors.get(1);
		motorToUpdate.addHours(20);
		
		motorToUpdate = null;
		
		List<Motor> needService = new ArrayList<Motor>();
		
		for (Motor someMotor : allMotors) {
			if (someMotor.isPastTimeForService() == true) {
				needService.add(someMotor);
			}		
		}
		
		for(Motor thing : needService) {
			System.out.println(thing.getSerialNumber());			
		}
		
		needService = null;
		
		List<Motor> copy = new ArrayList<Motor>();
		
		for(Motor thisMotor : allMotors) {
			copy.add(thisMotor);
		}
		
		copy.remove(0);
		
		List<Motor> anotherCopy = new ArrayList<Motor>(allMotors);
		
		Motor foundMotor = null;
		
		Motor matchingMotor = new Motor("BB", 0);
		
		for(Motor thisMotor : allMotors) {
			if(matchingMotor.equals(thisMotor)) {
				foundMotor = thisMotor;
				break;
				}
			}
		
		if(foundMotor != null) {
			System.out.println("Found " + foundMotor);
		}
		
		int position = allMotors.indexOf(matchingMotor);
		Motor motorToChange = allMotors.get(position);
		motorToChange.addHours(10);
		
		int difference = aMotor.compareTo(secondMotor);
		if(difference > 0) {
			System.out.println("AMotor is bigger than secondmotor by " + difference);
		}
		
		Motor smallest = Collections.max(allMotors);
		System.out.println("Largest is " + smallest);
		
		Motor gg = new Motor("GG", 10);
		Motor hh = new Motor("HH", 20);
		Motor jj = new Motor("JJ", 20);
		gg.addHours(34);
		hh.addHours(5);
		jj.addHours(5);
		
		allMotors.add(gg);
		allMotors.add(hh);
		allMotors.add(jj);
		
		Collections.sort(allMotors);
		Collections.reverse(allMotors);
		
		System.out.println("Sorted Order");
		
		for(Motor thisMotor : allMotors) {
			System.out.println(thisMotor);
		}
	}

}
